export function init(O, nodeArr, linkArr) {
  let $ = go.GraphObject.make;
  if (O.myDiagram) {
    O.myDiagram.div = null
  }
  let _O = O
  O.myDiagram =
    $(go.Diagram, "myDiagramDiv",
      {
        initialAutoScale: go.Diagram.Uniform,
        contentAlignment: go.Spot.Center,
        layout:
          $(go.ForceDirectedLayout,
            {maxIterations: 200, defaultSpringLength: 30, defaultElectricalCharge: 100})
      });

  O.myDiagram.nodeTemplate =
    $(go.Node, "Vertical",
      {locationSpot: go.Spot.Center, reshapable: true},
      $(go.Picture,
        {width: 60, height: 60, margin: 0, background: "#FFF"}, new go.Binding("source", O.switchImg)),
      $(go.TextBlock,
        {alignment: go.Spot.Center, font: "bold 16px sans-serif"},
        new go.Binding("text", "key")),
    );

  O.myDiagram.groupTemplate =
    $(go.Group, "Vertical",
      $(go.Panel, "Auto",
        $(go.Shape, "RoundedRectangle",  // surrounds the Placeholder
          {
            parameter1: 14,
            fill: "#FFF"
          }),
        $(go.Placeholder,    // represents the area of all member parts,
          {padding: 5})  // with some extra padding around them
      ),
      $(go.TextBlock,         // group title
        {alignment: go.Spot.Center, font: "Bold 12pt Sans-Serif"},
        new go.Binding("text", "key"))
    );

  O.myDiagram.linkTemplate =
    $(go.Link,
      {relinkableFrom: true, relinkableTo: true},
      $(go.Shape,
        {stroke: "black", strokeWidth: '1'}),
      $(go.Panel, "Auto",
        {
          cursor: "pointer"
        }
      )
    );

  O.myDiagram.model = new go.GraphLinksModel(nodeArr, linkArr);
}
